package auth_ctrl

import (
	"admin-system/internal/request"
	"admin-system/internal/service/auth_svc"
	"admin-system/pkg/error_code"
	"admin-system/pkg/response"
	"github.com/gin-gonic/gin"
	"log/slog"
)

type RoleController struct {
	RoleService *auth_svc.RoleService
}

func NewRoleController(RoleService *auth_svc.RoleService) *RoleController {
	return &RoleController{
		RoleService: RoleService,
	}
}

// GetRoleList
// @Summary 获取角色列表
// @Description 获取角色列表
func (r *RoleController) GetRoleList(c *gin.Context) {
	roleList, err := r.RoleService.GetUserAllRoles(c)
	if err != nil {
		slog.Any("获取角色列表失败", err)
		response.Fail(c, error_code.ErrInternalServer, "获取角色列表失败")
	}
	response.Success(c, roleList)
}

func (r *RoleController) CreateRole(c *gin.Context) {
}

func (r *RoleController) UpdateRole(c *gin.Context) {
}

func (r *RoleController) DeleteRole(c *gin.Context) {
}

// assignMenuToRole
// @Summary 分配角色
func (r *RoleController) AssignMenuToRole(c *gin.Context) {
	var reqAssignMenuToRole request.AssignMenuToRoleRequest
	// 接口中获取参数
	if err := c.ShouldBindJSON(&reqAssignMenuToRole); err != nil {
		slog.Any("参数错误", err)
		response.Fail(c, error_code.ErrInvalidParams, "参数错误")
	}
	// 调用role_service 将菜单绑定到角色
	if err := r.RoleService.AssignMenuToRole(c, reqAssignMenuToRole.RoleID, reqAssignMenuToRole.MenuIds); err != nil {
		slog.Any("分配菜单失败", err)
		response.Fail(c, error_code.ErrInternalServer, "分配菜单失败")
	}
	response.Success(c, nil)
}
